****APPENDIX TABLE E7-E8****

cd "$main_dir/output/tables/appendix_e"

global basic 	marital edu
global econ	    employment_status occupation income imputed_income
global design 	survey_year age language
global polit    ideology party_member

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

capture program drop standardize_var
program define standardize_var
	
	args var
	
	cap drop z*
	local varlist trust_fed_govt_med wgrowth_rate_1 `var'
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

gen dummy = 1 if trust_fed_govt_med!=.
bys idpers: egen total_obs = total(dummy)

xtset idpers survey_year

cap drop dln_real_income																			
gen dln_real_income = d.ln_real_income

cap drop sample income_sample
gen sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=15 & age!=.
gen income_sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=18 & age!=. & total_real_income_with_0_obs>=0.5*(age-18) & total_real_income_with_0_obs!=.

egen canton_survey_year = group(canton survey_year)

//--------------------------------------------------------
//Create Table E7
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt_med wgrowth_rate_1 wincome_growth_1 if sample==1 & total_real_income_with_0_obs>1 & total_real_income_with_0_obs!=. & age>=18 & age!=., absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob) 
standardize_var wincome_growth_1
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zwincome_growth_1 if e(sample)==1, absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, replace dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, Yes, ///
																			Survey Year FE, Yes, ///
																			Canton FE x Survey Year FE, No, ///
																			Sample, 2+ Years) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zwincome_growth_1)

//Column 2
qui reghdfe trust_fed_govt_med wgrowth_rate_1 wincome_growth_1 if sample==1 & total_real_income_with_0_obs>1 & total_real_income_with_0_obs!=. & age>=18 & age!=., absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob) 
standardize_var wincome_growth_1
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zwincome_growth_1 if e(sample)==1, absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, No, ///
																			Survey Year FE, No, ///
																			Canton FE x Survey Year FE, Yes, ///
																			Sample, 2+ Years) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zwincome_growth_1)


//Column 3
qui reghdfe trust_fed_govt_med wgrowth_rate_1 wincome_growth_1 if sample==1 & total_real_income_with_0_obs>=(2/3)*(age-18) & total_real_income_with_0_obs!=. & age>=18 & age!=., absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob) 
standardize_var wincome_growth_1
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zwincome_growth_1 if e(sample)==1, absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, Yes, ///
																			Survey Year FE, Yes, ///
																			Canton FE x Survey Year FE, No, ///
																			Sample, 2-3 Working Life) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zwincome_growth_1)
																			
//Column 4
qui reghdfe trust_fed_govt_med wgrowth_rate_1 wincome_growth_1 if sample==1 & total_real_income_with_0_obs>=(2/3)*(age-18) & total_real_income_with_0_obs!=. & age>=18 & age!=., absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob) 
standardize_var wincome_growth_1
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zwincome_growth_1 if e(sample)==1, absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, No, ///
																			Survey Year FE, No, ///
																			Canton FE x Survey Year FE, Yes, ///
																			Sample, 2-3 Working Life) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zwincome_growth_1)																			

//Column 5
qui reghdfe trust_fed_govt_med wgrowth_rate_1 dln_real_income if income_sample==1, absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
standardize_var dln_real_income
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zdln_real_income if e(sample)==1, absorb(canton $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, Yes, ///
																			Survey Year FE, Yes, ///
																			Canton FE x Survey Year FE, No, ///
																			Sample, Core) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zdln_real_income)

//Column 6
qui reghdfe trust_fed_govt_med wgrowth_rate_1 dln_real_income if income_sample==1, absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
standardize_var dln_real_income
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zdln_real_income if e(sample)==1, absorb(canton_survey_year $basic $design employment_status occupation imputed_income $polit idpers) cluster(idhous yob)
outreg2 using table_e7.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
																			Canton FE, No, ///
																			Survey Year FE, No, ///
																			Canton FE x Survey Year FE, Yes, ///
																			Sample, Core) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zdln_real_income)


//--------------------------------------------------------
//Create Table E8 (Panel A)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt_med wgrowth_rate_1 sd_inflation if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
standardize_var sd_inflation
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zsd_inflation if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_e8_panel_a.doc, replace dec(3) nocons addtext(Individual FE, Yes, ///
													   Canton FE, Yes, ///
													   Survey Year FE, Yes, ///
													   Canton FE x Survey Year FE, No) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zsd_inflation)

//Columns 2-5													   
local varlist wprop_unrest_1 wprop_affect_epidemic_1 wbank_crisis_1
foreach var of local varlist {
	qui reghdfe trust_fed_govt_med wgrowth_rate_1 `var' if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt_med zwgrowth_rate_1 z`var' if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
	outreg2 using table_e8_panel_a.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
													   Canton FE, Yes, ///
													   Survey Year FE, Yes, ///
													   Canton FE x Survey Year FE, No) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 z`var')												
}													   
													   
//--------------------------------------------------------
//Create Table E8 (Panel B)
//--------------------------------------------------------													   

//Column 1
qui reghdfe trust_fed_govt_med wgrowth_rate_1 sd_inflation if sample==1, absorb(canton_survey_year $basic $design $econ $polit idpers) cluster(idhous yob)
standardize_var sd_inflation
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zsd_inflation if e(sample)==1, absorb(canton_survey_year $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_e8_panel_b.doc, replace dec(3) nocons addtext(Individual FE, Yes, ///
													   Canton FE, No, ///
													   Survey Year FE, No, ///
													   Canton FE x Survey Year FE, Yes) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 zsd_inflation)												 

//Columns 2-5													   
local varlist wprop_unrest_1 wprop_affect_epidemic_1 wbank_crisis_1
foreach var of local varlist {
	qui reghdfe trust_fed_govt_med wgrowth_rate_1 `var' if sample==1, absorb(canton_survey_year $basic $design $econ $polit idpers) cluster(idhous yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt_med zwgrowth_rate_1 z`var' if e(sample)==1, absorb(canton_survey_year $basic $design $econ $polit idpers) cluster(idhous yob)
	outreg2 using table_e8_panel_b.doc, append dec(3) nocons addtext(Individual FE, Yes, ///
													   Canton FE, No, ///
													   Survey Year FE, No, ///
													   Canton FE x Survey Year FE, Yes) addstat("No. of Respondents", `=e(df_a_nested)') keep(zwgrowth_rate_1 z`var')													
}	

